package client

import (
	"github.com/gin-gonic/gin"
	"likeadmin/admin/schemas/req"
	"likeadmin/admin/service/client"
	"likeadmin/config"
	"likeadmin/core"
	"likeadmin/core/request"
	"likeadmin/core/response"
	"likeadmin/middleware"
	"likeadmin/util"
)

var ReportGroup = core.Group("/client", newReportHandler, regReport, middleware.TokenAuth())

func newReportHandler(srv client.IRechargeReportService) *reportHandler {
	return &reportHandler{srv: srv}
}

func regReport(rg *gin.RouterGroup, group *core.GroupBase) error {
	return group.Reg(func(handle *reportHandler) {
		rg.GET("/recharge_report/list", handle.list)
		rg.GET("/recharge_report/statistic", handle.statistic)
	})
}

type reportHandler struct {
	srv client.IRechargeReportService
}

// list report列表
func (hd reportHandler) list(c *gin.Context) {
	var page request.PageReq
	var listReq req.RechargeReportListReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
		return
	}
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
		return
	}
	res, err := hd.srv.List(c, page, listReq)
	response.CheckAndRespWithData(c, res, err)
}

// list report列表
func (hd reportHandler) statistic(c *gin.Context) {

	var listReq req.RechargeReportListReq

	if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &listReq)) {
		return
	}
	adminId := config.AdminConfig.GetAdminId(c)
	res, err := hd.srv.Statistic(adminId, listReq)
	response.CheckAndRespWithData(c, res, err)
}
